/*
 * Copyright 2021-2023 NXP
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 * contributors may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "ddr_lp.h"
#include "ddr_init.h"

/* DDR PHY Configuration and Status registers */
const uint32_t csr_to_store[] = {
	0x00001690U,
	0x00001718U,
	0x0001451cU,
	0x0001651cU,
	0x0001851cU,
	0x0001a51cU,
	0x00014520U,
	0x00016520U,
	0x00018520U,
	0x0001a520U,
	0x000003f0U,
	0x000023f0U,
	0x000043f0U,
	0x000063f0U,
	0x000083f0U,
	0x0000a3f0U,
	0x0000c3f0U,
	0x0000e3f0U,
	0x000103f0U,
	0x000123f0U,
	0x000146b0U,
	0x000166b0U,
	0x000186b0U,
	0x0001a6b0U,
	0x000146b4U,
	0x000166b4U,
	0x000186b4U,
	0x0001a6b4U,
	0x000146d0U,
	0x000166d0U,
	0x000186d0U,
	0x0001a6d0U,
	0x000146d4U,
	0x000166d4U,
	0x000186d4U,
	0x0001a6d4U,
	0x00014b50U,
	0x00016b50U,
	0x00018b50U,
	0x0001ab50U,
	0x00014b4cU,
	0x00016b4cU,
	0x00018b4cU,
	0x0001ab4cU,
	0x00014b70U,
	0x00016b70U,
	0x00018b70U,
	0x0001ab70U,
	0x00014b6cU,
	0x00016b6cU,
	0x00018b6cU,
	0x0001ab6cU,
	0x00014640U,
	0x00016640U,
	0x00018640U,
	0x0001a640U,
	0x0001463cU,
	0x0001663cU,
	0x0001863cU,
	0x0001a63cU,
	0x00014638U,
	0x00016638U,
	0x00018638U,
	0x0001a638U,
	0x00014634U,
	0x00016634U,
	0x00018634U,
	0x0001a634U,
	0x00014630U,
	0x00016630U,
	0x00018630U,
	0x0001a630U,
	0x0001462cU,
	0x0001662cU,
	0x0001862cU,
	0x0001a62cU,
	0x00014628U,
	0x00016628U,
	0x00018628U,
	0x0001a628U,
	0x00014624U,
	0x00016624U,
	0x00018624U,
	0x0001a624U,
	0x00014620U,
	0x00016620U,
	0x00018620U,
	0x0001a620U,
	0x00014664U,
	0x00016664U,
	0x00018664U,
	0x0001a664U,
	0x00014660U,
	0x00016660U,
	0x00018660U,
	0x0001a660U,
	0x0001465cU,
	0x0001665cU,
	0x0001865cU,
	0x0001a65cU,
	0x00014658U,
	0x00016658U,
	0x00018658U,
	0x0001a658U,
	0x00014654U,
	0x00016654U,
	0x00018654U,
	0x0001a654U,
	0x00014650U,
	0x00016650U,
	0x00018650U,
	0x0001a650U,
	0x0001464cU,
	0x0001664cU,
	0x0001864cU,
	0x0001a64cU,
	0x00014648U,
	0x00016648U,
	0x00018648U,
	0x0001a648U,
	0x00014644U,
	0x00016644U,
	0x00018644U,
	0x0001a644U,
	0x00014730U,
	0x00016730U,
	0x00018730U,
	0x0001a730U,
	0x00014734U,
	0x00016734U,
	0x00018734U,
	0x0001a734U,
	0x00014750U,
	0x00016750U,
	0x00018750U,
	0x0001a750U,
	0x00014754U,
	0x00016754U,
	0x00018754U,
	0x0001a754U,
	0x0001492cU,
	0x0001692cU,
	0x0001892cU,
	0x0001a92cU,
	0x00014928U,
	0x00016928U,
	0x00018928U,
	0x0001a928U,
	0x00014924U,
	0x00016924U,
	0x00018924U,
	0x0001a924U,
	0x00014920U,
	0x00016920U,
	0x00018920U,
	0x0001a920U,
	0x0001491cU,
	0x0001691cU,
	0x0001891cU,
	0x0001a91cU,
	0x00014918U,
	0x00016918U,
	0x00018918U,
	0x0001a918U,
	0x00014914U,
	0x00016914U,
	0x00018914U,
	0x0001a914U,
	0x00014910U,
	0x00016910U,
	0x00018910U,
	0x0001a910U,
	0x0001490cU,
	0x0001690cU,
	0x0001890cU,
	0x0001a90cU,
	0x000149bcU,
	0x000169bcU,
	0x000189bcU,
	0x0001a9bcU,
	0x000149b8U,
	0x000169b8U,
	0x000189b8U,
	0x0001a9b8U,
	0x000149b4U,
	0x000169b4U,
	0x000189b4U,
	0x0001a9b4U,
	0x000149b0U,
	0x000169b0U,
	0x000189b0U,
	0x0001a9b0U,
	0x000149acU,
	0x000169acU,
	0x000189acU,
	0x0001a9acU,
	0x000149a8U,
	0x000169a8U,
	0x000189a8U,
	0x0001a9a8U,
	0x000149a4U,
	0x000169a4U,
	0x000189a4U,
	0x0001a9a4U,
	0x000149a0U,
	0x000169a0U,
	0x000189a0U,
	0x0001a9a0U,
	0x0001499cU,
	0x0001699cU,
	0x0001899cU,
	0x0001a99cU,
	0x0001446cU,
	0x0001646cU,
	0x0001846cU,
	0x0001a46cU,
	0x000015e0U,
	0x000015e4U,
	0x00014850U,
	0x00016850U,
	0x00018850U,
	0x0001a850U,
	0x00001374U,
	0x00001388U,
	0x00014860U,
	0x00016860U,
	0x00018860U,
	0x0001a860U,
	0x00014870U,
	0x00016870U,
	0x00018870U,
	0x0001a870U,
	0x0000140cU,
	0x00001608U,
	0x00001618U,
	0x000003c8U,
	0x00000308U,
	0x00000c10U,
	0x00000c28U,
	0x00000c40U,
	0x00000c58U,
	0x00000c70U,
	0x00000c88U,
	0x00000ca0U,
	0x00000cb8U,
	0x000145fcU,
	0x000165fcU,
	0x000185fcU,
	0x0001a5fcU,
	0x00014600U,
	0x00016600U,
	0x00018600U,
	0x0001a600U,
	0x00014604U,
	0x00016604U,
	0x00018604U,
	0x0001a604U,
	0x00014608U,
	0x00016608U,
	0x00018608U,
	0x0001a608U,
	0x0001460cU,
	0x0001660cU,
	0x0001860cU,
	0x0001a60cU,
	0x00014610U,
	0x00016610U,
	0x00018610U,
	0x0001a610U,
	0x00014614U,
	0x00016614U,
	0x00018614U,
	0x0001a614U,
	0x00014618U,
	0x00016618U,
	0x00018618U,
	0x0001a618U,
	0x0001461cU,
	0x0001661cU,
	0x0001861cU,
	0x0001a61cU,
	0x000015f4U,
	0x00014430U,
	0x00016430U,
	0x00018430U,
	0x0001a430U,
	/* 2D training */
	0x00014730U,
	0x00016730U,
	0x00018730U,
	0x0001a730U,
	0x00014734U,
	0x00016734U,
	0x00018734U,
	0x0001a734U,
	0x00014750U,
	0x00016750U,
	0x00018750U,
	0x0001a750U,
	0x00014754U,
	0x00016754U,
	0x00018754U,
	0x0001a754U,
	0x000144f8U,
	0x000164f8U,
	0x000184f8U,
	0x0001a4f8U,
	0x000144f4U,
	0x000164f4U,
	0x000184f4U,
	0x0001a4f4U,
	0x000144f0U,
	0x000164f0U,
	0x000184f0U,
	0x0001a4f0U,
	0x000144ecU,
	0x000164ecU,
	0x000184ecU,
	0x0001a4ecU,
	0x000144e8U,
	0x000164e8U,
	0x000184e8U,
	0x0001a4e8U,
	0x000144e4U,
	0x000164e4U,
	0x000184e4U,
	0x0001a4e4U,
	0x000144e0U,
	0x000164e0U,
	0x000184e0U,
	0x0001a4e0U,
	0x000144dcU,
	0x000164dcU,
	0x000184dcU,
	0x0001a4dcU,
	0x000144d8U,
	0x000164d8U,
	0x000184d8U,
	0x0001a4d8U,
};

size_t csr_to_store_size = ARRAY_SIZE(csr_to_store);

const uint32_t ddrc_to_store[] = {
	OFFSET_DDRC_DRAMTMG2,
	OFFSET_DDRC_RANKCTL,
	OFFSET_DDRC_INIT6,
	OFFSET_DDRC_INIT7,
	OFFSET_DDRC_DFITMG1,
	OFFSET_DDRC_SBRCTL
};

size_t ddrc_to_store_size = ARRAY_SIZE(ddrc_to_store);
